
<template>
  <div>
    <SearchForm
        @search="onSearch"
        @reset="onReset"
        :search-list="searchList" :search-params="searchParams">
    </SearchForm>

    <div class="table-layout">
      <el-card shadow="never">
        <div class="table-handle">
          <el-button type="primary" size="mini" icon="el-icon-plus" @click="onAdd">新增</el-button>
        </div>
        <div class="table-box">
          <el-table
              size="large"
              stripe
              border
              v-loading="loading"
              max-height="500px"
              :data="tableData"
              row-key="id"
              :default-expand-all="true"
              :tree-props="{children: 'children'}"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(255, 255, 255, 0.8)"
              @selection-change="onSelect"
          >
            <el-table-column prop="name" label="名称"/>
            <el-table-column prop="path" label="路径"/>
            <el-table-column prop="icon" label="图标"/>
            <el-table-column prop="sort" label="顺序"/>
            <el-table-column prop="visible" label="是否可见">
              <template slot-scope="scope">
                <el-tag type="success" v-if="scope.row.visible">显示</el-tag>
                <el-tag type="info" v-else>隐藏</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="status" label="状态">
              <template slot-scope="scope">
                <el-tag type="success" v-if="scope.row.status === 0">启用</el-tag>
                <el-tag type="info" v-else>禁用</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="150px">
              <template slot-scope="scope">
                <el-button type="text" @click="onEdit(scope.row)">编辑</el-button>
                <el-button type="text" style="color: #F82222" @click="onDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-card>
    </div>
    <Add ref="addFormRef" @get-page="initData" />
  </div>
</template>
<script>

import crud from "@/mixins/crud";
import { http } from "@/api";
import Add from "./add.vue";
import {handleTree} from "@/utils/tree";
export default {
  name: "index",
  components: {
    Add
  },
  mixins: [crud],
  data() {
    return {
      request: {
        ...http.menu,
        page: undefined
      },
      searchList: [
        {
          label: '名称',
          prop: 'name',
          name: 'input',
          clearable: true
        },
      ],
      searchParams: {
        name: '',
      },
      defaultParams: {
      },
      tableData: [

      ]
    }
  },
  methods: {
    formatTableData(data) {
      return handleTree(data, 'id', 'parentId', 'children');
    }
  }
}
</script>

<style scoped lang="scss">

</style>
